<template>
<view>
<uni-search-bar :radius="100" @confirm="search"  @clear="clear" @cancel="clear"></uni-search-bar>
<view v-for="(item, idx) in actList" :key="idx" @tap="toDetail" class="act_sec" :data-recruit-id="item.id">
    <view class="img_sec">
        <image class="headimg" mode="scaleToFill" :src="item.deptheadurl?item.deptheadurl:'/static/images/defaultorg.png'"></image>
        <image class="thumb" mode="aspectFill" :src="item.thumb"></image>
    </view>
    <view class="title">{{item.title}}</view>
    <view class="desc">{{item.city ? item.city : item.province}} ｜ <text v-if="item.lastTime!=='即将开始'">报名截止：</text>{{item.lastTime}} ｜ 已报名：{{item.bnum}}人</view>
</view>
<view class="no_data" v-if="actList.length===0">暂无数据~</view>
<view class="no_more" v-if="actList.length!==0&&noMore">没有更多数据了~</view>
</view>
</template>

<script>
var t = require("../../utils/request.js"),
		config = require("../../utils/config.js").config,
    a = function (t) {
  return t && t.__esModule ? t : {
    default: t
  };
}(require("../../utils/api.js")),
    e = require("../../utils/util.js"),
    i = a.default.recruitList,
    o = a.default.dictionaryCounty,
    app = getApp();
export default {
  data() {
    return {
      level: 2,
      provinceId: "",
      cityId: "",
      page: 1,
      pageSize: 1,
      county: "全部",
      countyId: "",
      countyIdx: 0,
      category: "全部活动",
      categoryId: "",
      categoryIdx: 0,
      order: "智能筛选",
      orderIdx: 0,
      orderId: "",
	  keyword: '',
      countyList: [{
        name: "全部",
        id: "",
        _id: "",
        code: ""
      }],
      categoryList: [{
        name: "全部活动",
        value: "",
        _id: ""
      }],
      orderList: [{
        name: "智能筛选",
        value: "",
        _id: ""
      }],
      actList: [],
      noMore: !1
    };
  },

  components: {

  },
  props: {},
  onLoad: function (t) {
    var a = this;

    try {
      var i = uni.getStorageSync("areaId");
      console.log(i), this.setData({
        provinceId: i.p_id,
        cityId: i.c_id,
        countyId: i.d_id,
        level: i.level
      });
    } catch (t) {
      console.log(t);
    }

    this.getRecruitList().then(function (t) {
      if (t.data.success) {
        t.data.data.rows.length < 10 && a.setData({
          noMore: !0
        });
        var i = [];
        t.data.data.rows.forEach(function (t) {
          var a = new Date().getTime();
				t.recruit_start_time = new Date(t.startTime).getTime();
				t.recruit_finish_time = new Date(t.endTime).getTime();
				if (t.recruit_start_time > a) t.lastTime = "即将开始";else {
					var o = (0, e.calcLastTime)(t.recruit_finish_time);
					t.lastTime = o.day + "天" + o.hour + "小时";
				}
				t.distance = (t.distance / 1e3).toFixed(2);
				t.thumb = t.imageUrl ? config.host + "/sysFileInfo/preview?id=" + t.imageUrl : "/static/images/defaultorg.png";
				i.push(t);
			}), a.setData({
          actList: i,
          categoryList: a.categoryList.concat(t.data.category),
          orderList: a.orderList.concat(t.data.ordertype)
        }), a.getCountyList();
      }
    }).catch(function (t) {
      console.log(t.data.message);
    });
  },
  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () {},
  onPullDownRefresh: function () {
    var t = this;
    this.setData({
      page: 1,
      noMore: !1
    }), this.getRecruitList().then(function (a) {
      if (a.data.errCode === e.ERR_OK) {
        a.data.data.length < 10 && t.setData({
          noMore: !0
        });
        var i = [];
        a.data.data.forEach(function (t) {
          t.distance = (t.distance / 1e3).toFixed(2);
          var a = (0, e.calcLastTime)(t.recruit_finish_time);
          t.lastTime = a.day + "天" + a.hour + "小时", t.deptheadurl = t.deptheadurl ? t.deptheadurl + "?imageView2/2/w/40/h/40" : "/static/images/defaultorg.png", i.push(t);
        }), t.setData({
          actList: i
        }), uni.stopPullDownRefresh();
      }
    }).catch(function (t) {
      console.log(t.data.message);
    });
  },
  onReachBottom: function () {
    var t = this;

    if (!this.noMore) {
      var a = this.page;
      this.setData({
        page: ++a
      }), this.getRecruitList().then(function (a) {
        if (a.data.errCode === e.ERR_OK) {
          a.data.data.length < 10 && t.setData({
            noMore: !0
          });
          var i = [];
          a.data.data.forEach(function (t) {
            t.distance = (t.distance / 1e3).toFixed(2);
            var a = (0, e.calcLastTime)(t.recruit_finish_time);
            t.lastTime = a.day + "天" + a.hour + "小时", t.deptheadurl = t.deptheadurl ? t.deptheadurl + "?imageView2/2/w/40/h/40" : "/static/images/defaultorg.png", i.push(t);
          });
          var o = t.actList;
          t.setData({
            actList: o.concat(i)
          });
        }
      }).catch(function (t) {
        console.log(t.data.message);
      });
    }
  },
  onShareAppMessage: function () {
    return {
      title: "让公益更生活 让生活更公益",
      path: "/pages/index/index",
      imageUrl: "/static/images/zyh_logo.jpg"
    };
  },
  methods: {
	search(value) {
	this.keyword = value.value
	
    this.getRecruitList().then(res=>{
		console.log('res', res)
		res.data.data.rows.length < 10 && this.setData({
		  noMore: !0
		});
		let data = res.data.data.rows;
		let list = []
		data.forEach(item=>{
			
			let nowTime = new Date().getTime();
			item.recruit_start_time = new Date(item.startTime).getTime();
			item.recruit_finish_time = new Date(item.endTime).getTime();
			if (item.recruit_start_time > nowTime) item.lastTime = "即将开始";else {
				let o = (0, e.calcLastTime)(item.recruit_finish_time);
				item.lastTime = o.day + "天" + o.hour + "小时";
			}
			item.distance = (item.distance / 1e3).toFixed(2);
			let a = (0, e.calcLastTime)(item.recruit_finish_time);
			item.lastTime = a.day + "天" + a.hour + "小时", item.thumb = item.imageUrl ? config.host + "/sysFileInfo/preview?id=" + item.imageUrl : "/static/images/defaultorg.png", list.push(item);
		})
		this.setData({actList: list})
	})
	},
	clear() {
		this.keyword = ''
    this.getRecruitList().then(res=>{
		console.log(res)
		res.data.data.rows.length < 10 && this.setData({
		  noMore: !0
		});
		let data = res.data.data.rows;
		let list = []
		data.forEach(item=>{
			let nowTime = new Date().getTime();
			item.recruit_start_time = new Date(item.startTime).getTime();
			item.recruit_finish_time = new Date(item.endTime).getTime();
			if (item.recruit_start_time > nowTime) item.lastTime = "即将开始";else {
				let o = (0, e.calcLastTime)(item.recruit_finish_time);
				item.lastTime = o.day + "天" + o.hour + "小时";
			}
			item.distance = (item.distance / 1e3).toFixed(2);
			console.log(item.recruit_finish_time)
			let a = (0, e.calcLastTime)(item.recruit_finish_time);
			console.log(a)
			item.lastTime = a.day + "天" + a.hour + "小时", item.thumb = item.imageUrl ? config.host + "/sysFileInfo/preview?id=" + item.imageUrl : "/static/images/defaultorg.png", list.push(item);
		})
		this.setData({actList: list})
	})
	},
    countyChange: function (t) {
      var a = t.detail.value,
          e = this.countyList;
      2 == this.level ? this.setData({
        county: e[a].name,
        countyId: e[a].id
      }) : 1 == this.level && this.setData({
        county: e[a].name,
        cityId: e[a].id
      }), uni.pageScrollTo({
        scrollTop: 0,
        success: function () {
          uni.startPullDownRefresh();
        }
      });
    },
    categoryChange: function (t) {
      var a = t.detail.value,
          e = this.categoryList;
      this.setData({
        category: e[a].name,
        categoryId: e[a]._id
      }), uni.pageScrollTo({
        scrollTop: 0,
        success: function () {
          uni.startPullDownRefresh();
        }
      });
    },
    orderChange: function (t) {
      var a = t.detail.value,
          e = this.orderList;
      this.setData({
        order: e[a].name,
        orderId: e[a].value
      }), uni.pageScrollTo({
        scrollTop: 0,
        success: function () {
          uni.startPullDownRefresh();
        }
      });
    },
    getCountyList: function () {
      var a = this,
          e = {
        data: {
          api: o,
          typecode: "areatree",
          parentid: this.countyId || this.cityId || this.provinceId
        }
      };
      return (0, t.request)(e, "common", !1).then(function (t) {
        if (console.log(t), t.data.length > 0 && !a.countyId) {
          var e = [{
            name: "全部",
            id: "",
            _id: "",
            code: ""
          }];
          a.setData({
            countyList: e.concat(t.data)
          });
        } else a.setData({
          countyList: []
        });
      });
    },
    getRecruitList: function () {
			var a = {
				data: {
					api: i,
					pageNo: this.page,
					pageSize: this.pageSize,
					x: app.globalData.longitude,
					y: app.globalData.latitude,
					title: this.keyword
				}
			};
      return (0, t.request)(a, "normal", !0);
    },
    toDetail: function (t) {
      uni.navigateTo({
        url: "/pages/act/detail?id=" + t.currentTarget.dataset.recruitId
      });
    }
  }
};
</script>
<style>
page {
    width: 100%;
    height: auto;
    min-height: 100%;
    background: #f4f4f4;
    padding-bottom: 60rpx;
}

.select_wrapper {
    position: fixed;
    top: 0;
    /*  #ifdef  H5  */
    top:88rpx;
    /*  #endif  */
    left: 0;
    z-index: 99;
    width: 100%;
    height: 100rpx;
    justify-content: flex-start;
    background: #fff;
    border-top: 1rpx solid #e1e2e3;
    background: #f4f4f4;
    margin-bottom: 20rpx;
    padding-bottom: 10rpx;
}

.select_wrapper picker {
    flex: 0 0 33.33%;
    width: 33.33%;
    height: 90rpx;
}

.select_wrapper picker.double {
    flex: 0 0 50%;
    width: 50%;
    height: 90rpx;
}

.select_wrapper .select_sec {
    width: 100%;
    height: 90rpx;
    background: #fff;
}

.select_wrapper picker+picker>.select_sec {
    border-left: 1rpx solid #e1e2e3;
}

.select_sec .txt {
    flex: none;
    height: 100%;
    line-height: 90rpx;
}

.select_sec image {
    flex: 0 0 12rpx;
    width: 12rpx;
    height: 6rpx;
    margin-left: 12rpx;
}

.act_sec {
    width: 100%;
    min-height: 445rpx;
    height: auto;
    padding: 30rpx;
    margin-bottom: 10rpx;
    background: #fff;
}

.img_sec {
    position: relative;
    width: 100%;
    height: 280rpx;
    margin-bottom: 30rpx;
}

.img_sec .tag {
    position: absolute;
    top: -8rpx;
    left: -8rpx;
    z-index: 3;
    width: 160rpx;
    height: 52rpx;
}

.img_sec .tag image {
    z-index: 4;
}

.img_sec .tag image,.img_sec .tag text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.img_sec .tag text {
    z-index: 5;
    text-align: center;
    line-height: 48rpx;
    font-size: 24rpx;
    color: #fff;
}

.img_sec .thumb {
    width: 100%;
    height: 100%;
    border: 1rpx solid #e1e2e3;
    border-radius: 10rpx;
}

.img_sec .headimg {
    position: absolute;
    bottom: -40rpx;
    right: 30rpx;
    z-index: 5;
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;
}

.act_sec .title {
    width: 100%;
    margin-bottom: 20rpx;
    font-size: 32rpx;
    color: #333;
}

.act_sec .desc,.act_sec .title {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.act_sec .desc {
    font-size: 24rpx;
}
</style>